import { useThemeStore } from '@renderer/stores'
import { useEffect } from 'react'

const useInitWindow = () => {
  const { setTheme } = useThemeStore()

  useEffect(() => {
    //init初始化获取数据
    window.electron.ipcRenderer.send('init')
    window.electron.ipcRenderer.on('init', (_, data: any) => {
      if (data) {
        setTheme(data)
      }
    })
    window.electron.ipcRenderer.on('globalStateUpdated', (_, state) => setTheme(state))
  }, [])
}

export default useInitWindow
